<template>
  <div class="nav-bar">
    <div class="hp-header flex items-center px-4">
      <div class="hp-header-left h-full flex-1">
        <nav class="hp-breadcrumb">
          <ol class="items-center">
            <li>
              <span class="hp-breadcrumb-overlay-link flex items-center" @click="goHome">
                <span role="img" class="appIcon" style="display: inline-block">
                  <svg-icon icon-class="home-page" style="margin-right: 3px" />
                </span>
                智能训练与验证子系统
                <span v-if="!isHome" class="hp-breadcrumb-separator">/</span>
              </span>
            </li>
            <li v-if="!isHome">
              <span class="hp-breadcrumb-overlay-link">
                <el-popover placement="bottom-start" title="" trigger="hover" :visible-arrow="false">
                  <div class="breadcrumb-dropdown-menu">
                    <div class="tool-item" v-for="tool in mySpaceList" :key="tool.id + '_tool'" :class="{
                      'tool-item-selected': toolInfo.id == tool.id,
                    }" @click="handleChangeTool(tool)">
                      <div class="flex items-center">
                        <span role="img" class="appIcon">
                          <svg-icon :icon-class="tool.icon" width="16" height="16" />
                        </span>
                        <div class="flex-1" style="
                            margin-left: 5px;
                            text-align: left;
                            white-space: nowrap;
                            text-overflow: ellipsis;
                            overflow: hidden;
                          ">
                          {{ $t("homePage." + tool.nameEn) }}
                        </div>
                      </div>
                    </div>
                    <!-- <div class="dropdown-divider"></div>
                    <div class="tool-item" v-for="menu in mainMenuList" :key="menu.id + '_module'"
                      @click="handleChangeModule(menu)">
                      <div class="flex items-center">
                        <span role="img" class="appIcon">
                          <svg-icon :icon-class="menu.icon" width="16" height="16" />
                        </span>
                        <div class="flex-1" style="
                            margin-left: 5px;
                            text-align: left;
                            white-space: nowrap;
                            text-overflow: ellipsis;
                            overflow: hidden;
                          ">
                          {{ $t("homePage." + menu.nameEn) }}
                        </div>
                      </div>
                    </div> -->
                  </div>
                  <div slot="reference" class="hp-breadcrumb-menu flex items-center">
                    <div class="hp-breadcrumb-pr-name">
                      {{ $t("homePage." + toolInfo.nameEn) }}
                    </div>
                    <span role="img" class="appIcon">
                      <svg-icon icon-class="bottom-arrow" width="12" height="12" />
                    </span>
                  </div>
                </el-popover>
              </span>
            </li>
          </ol>
        </nav>
      </div>
      <div class="hp-header-right flex items-center">
        <!-- 暂时注释 -->
        <!-- <div class="hp-btn">
          <span role="img" class="appIcon">
            <el-popover placement="bottom" title="deepseek" trigger="hover">
              <svg-icon slot="reference" icon-class="deepseek" width="20" height="20" @click="handleDeepSeek()" />
            </el-popover>
          </span>
        </div> -->
        <div class="hp-btn">
          <span role="img" class="appIcon">
            <el-popover placement="bottom" :title="$t('setup.refresh')" trigger="hover">
              <svg-icon slot="reference" icon-class="refresh-page" width="14" height="14" @click="handleRefresh()" />
            </el-popover>
          </span>
        </div>
        <!-- <div class="hp-btn">
          <span role="img" class="appIcon">
            <el-popover placement="bottom" :title="$t('setup.setup')" trigger="hover">
              <svg-icon slot="reference" icon-class="system-setting" width="15" height="15"
                @click="dialogVisible = true" />
            </el-popover>
          </span>
        </div> -->
        <div class="ml-2">
          <div class="flex justify-center items-center">
            <span class="hp-badge">
              <el-popover placement="bottom-end" title="" trigger="hover" :visible-arrow="false">
                <div class="dropdown-menu">
                  <div class="menu-item mx-1" v-for="menu in avatarMenuList" :key="menu.id"
                    @click="handleMenuClick(menu)">
                    <div class="flex items-center">
                      <span role="img" class="appIcon" style="font-size: 16px; margin-right: 5px">
                        <svg-icon :icon-class="menu.icon" width="16" height="16" />
                      </span>
                      {{ $t("setup." + menu.nameEn) }}
                    </div>
                  </div>
                </div>
                <el-avatar slot="reference" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
                  :size="24"></el-avatar>
              </el-popover>
            </span>
          </div>
        </div>
      </div>
    </div>
    <el-dialog title="" :visible.sync="dialogVisible" width="50vw" custom-class="jtyj-dialog-setup"
      :before-close="handleClose">
      <SetUp @handleClose="handleClose"></SetUp>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
import SetUp from "./set-up-dialog.vue";
export default {
  data() {
    return {
      dialogVisible: false,
    };
  },
  props: {
    isHome: {
      type: Boolean,
      default: true,
    },
  },
  components: {
    SetUp,
  },
  computed: {
    ...mapState({
      avatarMenuList: (state) => state.homePage.avatarMenuList,
      mainMenuList: (state) => state.homePage.mainMenuList,
      mySpaceList: (state) => state.homePage.mySpaceList,
      toolInfo: (state) => state.homePage.toolInfo,
    }),
  },
  created() {
  },
  methods: {
    // 返回首页
    goHome() {
      this.$router.push({
        path: "/",
      });
    },
    // 刷新当前页面
    handleRefresh() {
      location.reload(true);
    },
    // 打开deepseek
    handleDeepSeek() {
      this.$message.info("功能开发中...");
    },
    // 控制设置弹框是否展示
    handleClose() {
      this.dialogVisible = false;
    },
    // 切换工具展示
    handleChangeTool(tool) {
      switch (tool.nameEn) {
        case "model-manage-tool":
          this.$router.push({ name: "perceptualSampleDataManagement" });
          this.handleChangeToolSuccess(tool)
          break;
        case "scenario-edit-tool":
          this.$router.push({ name: "trainingAlgorithmEnvironmentImageManagement" });
          this.handleChangeToolSuccess(tool)
          break;
        case "experiment-design-tool":
          this.$router.push({ name: "preprocessingAlgorithmEnvironmentImageManagement" });
          this.handleChangeToolSuccess(tool)
          break;
        case "evaluation-analysis-tool":
          this.$router.push({ name: "algorithmReleaseEnvironmentImageManagement" });
          this.handleChangeToolSuccess(tool)
          break;
        case "simulation-run-tool":
          // this.$router.push({ name: "SimulationRunTool" });
          // this.handleChangeToolSuccess(tool)
          this.$message.error(`暂未开发`);
          break;
        default:
          this.$message.error(`暂未开发`);
          break;
      }
    },
    // 切换工具成功后的回调
    handleChangeToolSuccess(tool) {
      this.$emit("updateToolInfo", tool);
    },
    // 切换首页的三个模块
    handleChangeModule(module) {
      this.$router.push({ name: "HomePage", query: { module: module.id } });
    },
    // 点击头像的下拉菜单
    handleMenuClick(menu) {
      switch (menu.name) {
        case "账号设置":
          this.dialogVisible = true;
          break;
        case "退出登录":
          this.logout();
          break;
      }
    },
    async logout() {
      this.$confirm("确定注销并退出系统吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.dispatch("LogOut").then(() => {
            location.href = "/index";
          });
        })
        .catch(() => { });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "../../assets/styles/themeConfig/themeConfig.scss";

.nav-bar {
  height: 100%;

  .hp-header {
    min-height: 40px;

    .hp-header-left {
      .hp-breadcrumb {
        margin: 0;
        padding: 0;
        list-style: none;
        font-size: 16px;
        color: var(--ui-breadcrumb-base-color);

        >ol {
          flex-wrap: wrap;
          margin: 0;
          padding: 0;
          list-style: none;
          display: flex;

          .hp-breadcrumb-overlay-link {
            border-radius: 6px;
            margin: 0 -4px;
            padding: 0 4px;
            display: flex;
            cursor: pointer;

            .hp-breadcrumb-menu {
              min-width: 0;
              max-width: 100%;
              color: var(--app-header-text-color-hover);
              font-weight: 500;
              justify-content: start;
              cursor: pointer;

              .hp-breadcrumb-pr-name {
                color: var(--app-header-text-color-hover);
                font-weight: 500;
                white-space: nowrap;
                text-overflow: ellipsis;
                margin-right: 5px;
              }
            }

            &:hover {
              color: var(--ui-text-color);
              background-color: var(--ui-item-hover-bg);
            }
          }

          .hp-breadcrumb-separator {
            margin: 0 8px;
            color: var(--ui-breadcrumb-base-color);
          }
        }
      }
    }

    .hp-header-right {
      gap: 0 4px;
      margin-left: auto;
      flex-shrink: 0;

      .hp-btn {
        width: 24px;
        height: 24px;
        line-height: 24px;
        font-weight: normal;
        border-radius: 8px;
        display: inline-flex;
        justify-content: center;
        align-items: center;
        user-select: none;
      }

      .hp-badge {
        box-sizing: border-box;
        color: var(--ui-text-color);
        font-size: 14px;
        margin: 0;
        padding: 0;
        width: 24px;
        height: 24px;
        line-height: 1;
        display: inline-block;
        position: relative;
      }
    }
  }
}
</style>